/**
 * 
 */
package com.gopay.common.cps.dao.deposit.impl;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.deposit.DepositInfoQueryDAO;
import com.gopay.common.domain.acps.LockSource;
import com.gopay.common.domain.deposit.CorpDepositInfo;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 保证金信息表
 * 
 * @DepositInfoQueryDAOImpl.java
 * @author zhuliang
 * @2017-4-13 下午1:11:52 www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("depositInfoQueryDAO")
public class DepositInfoQueryDAOImpl extends BaseDAOImpl<CorpDepositInfo, Serializable> implements DepositInfoQueryDAO {

    //根据custId获取保证金信息表数据
    @Override
    public CorpDepositInfo getDepositByCustId(String custId){
        DetachedCriteria criteria = DetachedCriteria.forClass(CorpDepositInfo.class);
        criteria.add(Restrictions.eq("custId", custId));
        List<CorpDepositInfo> rsList = this.findByCriteria(criteria);
        return rsList!=null&&rsList.size()>0?rsList.get(0):null;
    }

    @Override
    public List<CorpDepositInfo> getDepositListByCustId(String paymentFlag) {
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("paymentFlag", paymentFlag);
        return super.findByHql("from CorpDepositInfo where paymentFlag=:paymentFlag ", params);
    }

    @Override
    public CorpDepositInfo getDepositAmtByAcctId(String acctId) {
        DetachedCriteria criteria = DetachedCriteria.forClass(CorpDepositInfo.class);
        criteria.add(Restrictions.eq("gnstAcct", acctId));
        List<CorpDepositInfo> rsList = this.findByCriteria(criteria);
        return rsList!=null&&rsList.size()>0?rsList.get(0):null;
    }

    @Override
    public boolean isDepositLocked(String custId) {
        DetachedCriteria criteria = DetachedCriteria.forClass(CorpDepositInfo.class);
        criteria.add(Restrictions.eq("custId", custId));

        List<CorpDepositInfo> list = this.findByCriteria(criteria);
        if (list != null && list.size() == 1
                && LockSource.DEPO_03.value.equals(list.get(0).getLockSource())) {
            return true;
        } else {
            return false;
        }
    }
}
